import java.util.ArrayList;
import java.util.List;

/**
 * @author SaoE
 * @date 2025/3/25 21:34
 */
public class _148 {
    public ListNode sortList(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        List<Integer> list = new ArrayList<>();
        ListNode cur = head;
        while (cur != null){
            list.add(cur.val);
            cur = cur.next;
        }
        cur = head;
        list.sort(Integer::compare);
        for (int i = 0; i < list.size(); i++) {
            head.val = list.get(i);
            head = head.next;
        }
        return cur;
    }
}
